//
//  FLConusViewController.m
//  FeeLing
//
//  Created by 乔光玉 on 2019/1/4.
//  Copyright © 2019年 大仙儿飘. All rights reserved.
//
#import "UITextView+Placeholder.h"
#import "FLSuccessCommitView.h"
#import "FLUseragreementViewController.h"
#import "FLConusViewController.h"
#import "FLStijiaochenggongView.h"
@interface FLConusViewController ()<UITextViewDelegate>

{
    FLSuccessCommitView *_successview;
    FLStijiaochenggongView * _shivaiview;
}

@property(nonatomic,strong)UITextView * useoftermsTextView;
@end

@implementation FLConusViewController

-(void)backclick{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#2B2D5C"];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    UIView *navview = [[UIView alloc] init];
    navview.frame = CGRectMake(0,0,SCREENWIDTH,64);
    
    navview.backgroundColor = [UIColor colorWithHexString:@"32346A"];
    [self.view addSubview:navview];
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0,30,SCREENWIDTH,25);
    label.text = NSLocalizedString(@"lianxiwomen", nil);
    label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
    label.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    label.textAlignment = NSTextAlignmentCenter;
    label.alpha = 1;
    label.numberOfLines = 0;
    [self.view addSubview:label];
    
    UIButton * back = [UIButton new];
    [back setImage:[UIImage imageNamed:@"返回首页_slices"] forState:UIControlStateNormal];
    back.frame = CGRectMake(12, 27, 30, 30);
    [back addTarget:self action:@selector(backclick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back];
    
    
    _useoftermsTextView=[[UITextView alloc]init];
    _useoftermsTextView.backgroundColor = [UIColor colorWithHexString:@"#24234F"];
    
    _useoftermsTextView.frame = CGRectMake(15, 87, SCREENWIDTH-30, 210);
    if (SCREENHEIGHT>800) {
        navview.frame = CGRectMake(0,0,SCREENWIDTH,64+20);
        label.frame = CGRectMake(0,30+20,SCREENWIDTH,25);
        back.frame = CGRectMake(12, 27+20, 30, 30);
        _useoftermsTextView.frame =CGRectMake(15, 87+20, SCREENWIDTH-30, 210-20);
    }
    _useoftermsTextView.font =  [UIFont fontWithName:@"PingFangSC-Regular" size:13];
    _useoftermsTextView.textColor = [UIColor colorWithHexString:@"#8184C1"];
    _useoftermsTextView.layer.cornerRadius = 5;
    _useoftermsTextView.clipsToBounds = YES;
    _useoftermsTextView.placeHolder = NSLocalizedString(@"shuoming", nil);
    _useoftermsTextView.delegate = self;
    _useoftermsTextView.editable = YES;
    [self.view addSubview:_useoftermsTextView];
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setTitle:NSLocalizedString(@"lijifasong", nil) forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(15, 371, SCREENWIDTH-30, 60);
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,SCREENWIDTH-30,60);
    gl.startPoint = CGPointMake(0.08, 0.18);
    gl.endPoint = CGPointMake(1, 0.89);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:252/255.0 green:86/255.0 blue:142/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:252/255.0 green:86/255.0 blue:142/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:246/255.0 green:55/255.0 blue:51/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(0), @(1.0f)];
    gl.cornerRadius = 30;
    [button.layer insertSublayer:gl atIndex:0];
    [button addTarget:self action:@selector(buttonclick:) forControlEvents:UIControlEventTouchUpInside];
    
    button.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size: 18];
    button.layer.cornerRadius = 30;
    button.clipsToBounds = YES;
    [self.view addSubview:button];
    
    UILabel * chulilabel = [[UILabel alloc] init];
    chulilabel.frame = CGRectMake(15,_useoftermsTextView.bottom+10,SCREENWIDTH-15,40);
    chulilabel.alpha = 1;
    chulilabel.textAlignment = NSTextAlignmentLeft;
    chulilabel.numberOfLines = 2;
    
    chulilabel.text = NSLocalizedString(@"chulilabeltext", nil);
    chulilabel.textColor = [UIColor colorWithHexString:@"#DFE0FF"];
    chulilabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    [self.view addSubview:chulilabel];
}
-(void)buttonclick:(UIButton *)sender{
    
    if (_useoftermsTextView.text!=nil&&_useoftermsTextView.text.length>=3) {
        AVObject * product = [AVObject objectWithClassName:@"yijian"];
        [product setObject:_useoftermsTextView.text forKey:@"jiangxi"];
        [product saveEventually:^(BOOL succeeded, NSError * _Nullable error) {
            if (succeeded) {
                _successview = [[FLSuccessCommitView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 80)];
                
                [self.view addSubview:_successview];
                [UIView animateWithDuration:0.2 animations:^{
                    if (SCREENHEIGHT>800) {
                        _successview.frame =CGRectMake(0, SCREENHEIGHT-80-34, SCREENWIDTH, 80);
                    }else{
                        _successview.frame =CGRectMake(0, SCREENHEIGHT-80, SCREENWIDTH, 80);
                    }
                    
                } completion:^(BOOL finished) {
                    
                    
                    [UIView animateWithDuration:0.2 delay:1 options:UIViewAnimationOptionCurveLinear animations:^{
                        
                        _successview.frame =CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 80);
                    } completion:^(BOOL finished) {
                        
                        [_successview removeFromSuperview];
                         [self.navigationController popViewControllerAnimated:YES];
                    }];
                    
                }];

               
                
            }else{
                
                [MBProgressHUD showError:NSLocalizedString(@"tijiaojianyishibai", nil) toView:self.view];
            }
            
        }];
    }else{
        
        _shivaiview = [[FLStijiaochenggongView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 80)];
        
        [self.view addSubview:_shivaiview];
        [UIView animateWithDuration:0.2 animations:^{
            if (SCREENHEIGHT>800) {
                _shivaiview.frame =CGRectMake(0, SCREENHEIGHT-80-34, SCREENWIDTH, 80);
            }else{
                _shivaiview.frame =CGRectMake(0, SCREENHEIGHT-80, SCREENWIDTH, 80);
            }
            
        } completion:^(BOOL finished) {
            
            
            [UIView animateWithDuration:0.2 delay:1 options:UIViewAnimationOptionCurveLinear animations:^{
                
                _shivaiview.frame =CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 80);
            } completion:^(BOOL finished) {
                
                [_shivaiview removeFromSuperview];
            }];
            
        }];
    }
    
    
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
